package com.kly.cashmall.module.index.adapter;

import android.widget.ProgressBar;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.kly.cashmall.R;
import com.kly.cashmall.bean.ProductListBean;
import com.kly.cashmall.utils.function.CommonUtils;
import com.kly.cashmall.utils.function.GlideUtils;

import java.util.List;

/**
 * Created by
 * on 2019/4/28.
 */
public class IndexProductAdapter extends BaseQuickAdapter<ProductListBean, BaseViewHolder> {
    public IndexProductAdapter(@Nullable List<ProductListBean> data) {
        super(R.layout.item_product_list, data);
    }

    @Override
    protected void convert(@NonNull BaseViewHolder holder, ProductListBean item) {
        TextView mItemTitle = holder.getView(R.id.item_title);
        TextView mItemTip = holder.getView(R.id.item_tip);
        TextView mItemAmount = holder.getView(R.id.item_amount);
        TextView mItemConfirm = holder.getView(R.id.item_confirm);
        ProgressBar mItemProgressBar = holder.getView(R.id.item_progress_bar);
        String icon = item.getCategoryLogo();
        if (icon != null) {
            GlideUtils.loadImage(getContext(), icon,holder.getView(R.id.item_logo));
        }
        mItemProgressBar.setProgress(item.getCategoryApplicationRatio());
        holder.setText(R.id.item_progress_bar_text,item.getCategoryApplicationRatio()+"%");
        mItemTitle.setText(item.getCategoryName());
        mItemTip.setText(item.getCategoryDesc());
        mItemAmount.setText(CommonUtils.setSymbol(item.getCategoryRange(),"₹",0.78f));
        holder.setText(R.id.item_confirm, item.getButtonName());
        if (item.getCategoryStatusOnline() == 1){
            holder.setImageResource(R.id.item_hot,R.mipmap.ic_hot);
        }else if (item.getCategoryStatusOnline() == 2){
            holder.setImageResource(R.id.item_hot,R.mipmap.ic_new);
        }
        holder.setVisible(R.id.item_hot,item.getCategoryStatusOnline() == 1 || item.getCategoryStatusOnline() == 2);
        if(item.isPermitApply()){
            if (item.getJumpType() == 0){
                mItemConfirm.setTextColor(getContext().getResources().getColor(R.color.color_955B00));
                mItemConfirm.setBackgroundResource(R.drawable.shape_index_button);
            }else {
                mItemConfirm.setTextColor(getContext().getResources().getColor(R.color.white));
                mItemConfirm.setBackgroundResource(R.drawable.shape_order_status_completed);
            }
        }else {
            mItemConfirm.setBackgroundResource(R.drawable.shape_home_unable_button);
            mItemConfirm.setTextColor(getContext().getResources().getColor(R.color.color_999999));
        }
    }
}
